"""
WSGI config for iot project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/
"""
# from gevent import monkey
# monkey.patch_all()
import os

import socketio
from gevent import monkey
monkey.patch_all()
from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'iot.settings')

dj_application = get_wsgi_application()



class WSGIAPP(socketio.WSGIApp):

    def __call__(self, environ, start_response):
        '''
        重写 __call__ 方法  加入自定义url  更多python中的wsgi应用 请自行搜索博客 或者自行查看源码
        :param environ: 请求信息
        :param start_response: 确定返回信息
        :return:
        '''
        path = environ['PATH_INFO']
        if 'socket.io' in path:
            return super(WSGIAPP, self).__call__(environ, start_response)
        return dj_application(environ, start_response)


from apps.websocket.apps import sio

application = WSGIAPP(sio)
